home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS08.ADF / C / SetWindow.c < prev    next >
C/C++ Source or Header  |  1986-04-02  |  4KB  |  108 lines

  1. /*
  2. Subject: ICONEXEC utility
  3. Date-Received: 22 Feb 86 06:37:26 GMT
  4. Sender: jcz@ncsu.UUCP
  5. Organization: SAS Institute Inc.
  6. Lines: 256
  7.  
  8. Here are two simple utilities that may make it easier to write code that
  9. runs from workbench.  The second utility IconExec allows you to run any
  10. arbitrary command from an Icon WITHOUT having to recompile a program
  11. everytime you wish to change what is run.  The other utility allows you
  12. to set the default window that will be used when an Icon is selected.
  13.  
  14. As a matter of short explaination, whenever an Icon is selected, the
  15. ToolWindow field is (supposed to be) copied into the initial startup
  16. message that is passed to your program.  The startup code (c.o) looks
  17. at that message and opens up that window by default.  In this way you can
  18. always associate a window with a program without having to open it in
  19. your code.  Unfortunately, Intuition (or whomever is responsible) fails
  20. to copy the ToolWindow field over and no window is opened currently.
  21. ICONEXEC takes that into account and opens up the window anyway (Until
  22. the parameter gets copied correctly in a later OS release) and sets it
  23. as the default window.
  24.  
  25. Once a window is established, the commands that are contained in the
  26. ToolTypes arrays are then executed one at a time.  More detailed information
  27. about how the Icons are organizied is in Chapter 4 of Volume1 in the 1.1
  28. Rom Kernal Manual, although the information is not critical to using
  29. the program.  If enough interest exists, I will create a tutorial on
  30. using Icons or whatever other information is desired in creating/accessing
  31. them from a program.
  32.  
  33. These programs were created in response to a request for being able to run
  34. programs such as MUSICRAFT which have no ICONS without Having to modify
  35. the program.  If you plan on using ICONEXEC for a commercial product, just
  36. contact me first.
  37. -----cut here for SetWindow.c------------
  38. */
  39. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  40. /* SetWindow - Set the ToolWindow for an ICON                            */
  41. /* (c) Copyright 1986 John A. Toebes, VIII   All rights reserved         */
  42. /*     120-H Northington Place,   Cary NC 27511   (919) 469-4210         */
  43. /*  This program may be used and modified for any purpose so long as     */
  44. /*  this copyright notice remains with the code and the program is not   */
  45. /*  sold and no charge is made for its use.                              */
  46. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  47.  
  48. /* To use:
  49.    1) Compile and link as any other program
  50.    2) Issue command to modify whatever Icon you wish to
  51.         SetWindow <icon> <window specifications>
  52. */
  53.  
  54. #include <stdio.h>
  55. #include <exec/types.h>
  56. #include <workbench/workbench.h>
  57. #include <workbench/icon.h>
  58. #include <workbench/startup.h>
  59.  
  60. int IconBase;
  61. extern struct WBStartup *WBenchMsg;
  62.  
  63. main(argc,argv)
  64. int argc;
  65. char *argv[];
  66. {
  67.    struct DiskObject *diskobj, *GetDiskObject();
  68.    char *savewindow;
  69.  
  70.    /* make sure we ran from CLI */
  71.    if (argc == 0) exit(1);
  72.  
  73.    /* make sure we have enough parms */
  74.    if (argc != 2 && argc != 3)
  75.       {
  76.       printf("Usage: %s <icon> [<windowspec>]\n", argv[0]);
  77.       exit(2);
  78.       }
  79.  
  80.    if ( (IconBase = OpenLibrary( ICONNAME, 1)) == NULL)
  81.       exit(2);
  82.  
  83.    /* get the icon from disk */
  84.    if ( (diskobj = GetDiskObject(argv[1])) == NULL)
  85.       {
  86.       printf("Cannot read icon for %s\n", argv[1]);
  87.       CloseLibrary( IconBase );
  88.       exit(3);
  89.       }
  90.  
  91.    /* remember what the previous window was */
  92.    savewindow = diskobj->do_ToolWindow;
  93.  
  94.    /* set it to what was requested */
  95.    diskobj->do_ToolWindow = (argc > 2) ? argv[2] : NULL;
  96.  
  97.    /* write the corrected ICON to disk */
  98.    if (!PutDiskObject( argv[1], diskobj))
  99.       printf("Cannot write new icon - code %d\n", IoErr() );
  100.  
  101.    /* restore the oldwindow and free the object */
  102.    diskobj->do_ToolWindow = savewindow;
  103.    FreeDiskObject( diskobj );
  104.  
  105.    CloseLibrary( IconBase );
  106. }
  107. /* -----end of SetWindow.c-------------  */
  108.